<?php

namespace app\admin\controller\vbot;

use app\common\controller\Backend;

/**
 * 变量管理
 *
 * @icon fa fa-circle-o
 */
class Variable extends Backend
{

    /**
     * vbotVariable模型对象
     * @var \app\admin\model\vbotVariable
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\VbotVariable;
        $this->view->assign("valueSourceList", $this->model->getValueSourceList());
    }

    /*
     * 获取变量值-用于管理员测试
     */
    public function view_variable($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds)) {
            if (!in_array($row[$this->dataLimitField], $adminIds)) {
                $this->error(__('You have no permission'));
            }
        }

        $VbotLib             = new \addons\vbot\library\VbotLib();
        $row->variable_value = $VbotLib->get_variable_value($row->toArray());

        $this->success(null, null, $row);
    }

}
